package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.*;

@WebServlet("/AcompanhadorContratoControle")
public class AcompanhadorContratoControle extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public AcompanhadorContratoControle() {
		super();
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String operacao = request.getParameter("operacao");

		if (operacao.equals("Pesquisar")) {
			
			ArrayList<String> filtros = new ArrayList<String>();

			filtros.add((request.getParameter("sel_cliente").isEmpty()) ? ""
					: request.getParameter("sel_cliente"));
			filtros.add((request.getParameter("sel_contrato").isEmpty()) ? ""
					: request.getParameter("sel_contrato"));
			filtros.add((request.getParameter("sel_situacao").isEmpty()) ? ""
					: request.getParameter("sel_situacao"));
			filtros.add((request.getParameter("sel_acompanhador").isEmpty()) ? ""
					: request.getParameter("sel_acompanhador"));
			
			ArrayList<Map<String, String>> contratos = new ArrayList<Map<String, String>>();
			ContratoDAO objDAO = new ContratoDAO();

			try {
				contratos = objDAO.getLista(filtros);
			} catch (SQLException e) {
				e.printStackTrace();
			}

			request.setAttribute("filtros", filtros);
			request.setAttribute("contratos", contratos);
			request.setAttribute("etapaAcompanhadorContrato", "segunda");

			RequestDispatcher view = request
					.getRequestDispatcher("listarAcompanhadorContrato.jsp");
			view.forward(request, response);
		}

	}
}